using System;
using System.IO;
using System.Collections;
using System.Windows.Forms;

namespace Patchy
{
    /// <summary>
    /// Summary description for FileOperations.
    /// </summary>
    public class FileOperations
    {
        public FileOperations() { }

        public void DoCopy(string targetDir, GroupHolder groupHolder)
        {
            try
            {
                foreach (MyGroup group in groupHolder.SortedGroupCollection)
                {
                    foreach (MyFile file in group.Files)
                    {
                        string path = Path.Combine(targetDir, file.ShortenedName);
                        string dir = Path.GetDirectoryName(path);
                        if (!Directory.Exists(dir))
                            Directory.CreateDirectory(dir);
                        File.Copy(file.OriginalName, path, true);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to copy file(s): " + ex.Message);
            }
        }
    }
}
